<?php
require_once 'kernel/form.php';

General::getTpl()->assign('extraTitle',"Admin-Login");
if(!Admin::isLoggedIn()) {
	// Form-Data
	$formField = array();
	$formField[0]['fieldName'] = "Name";
	$formField[0]['fieldType'] = Form::$TYPE_TEXT;
	$formField[0]['fieldDefaultValue'] = "";
	$formField[0]['fieldCheck'] = true;
	$formField[0]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
	
	$formField[1]['fieldName'] = "Passwort";
	$formField[1]['fieldType'] = Form::$TYPE_PASSWORD;
	$formField[1]['fieldDefaultValue'] = "";
	$formField[1]['fieldCheck'] = true;
	$formField[1]['fieldCheckExtra'] = Form::$CHECK_TEXT_NOTEMPTY;
	    	
	$form = new Form();
	$form->initByData("Adminlogin",true,"Login!",$formField);
	
	// Done?
	if($form->completeCheck()) {
		// Output Message
		if(Admin::login($_POST['Name'],$_POST['Passwort'])) {
			General::getTpl()->assign('body','Erfolgreich!');
			header("LOCATION:".Settings::getInstance()->getSetting("General.urlToCMS"));
		}else{
			General::getTpl()->assign('errorMsg',General::getTpl()->get_template_vars('errorMsg')."<li>Falsche Logindaten</li>");
			Error::insertError("Fehlerhafter Adminlogin","Falsche Logindaten beim Adminlogin: Username: ".DB::parseVar($_POST['Name']),"Adminlogin");
			$form->outputFormular('body','formular.html');
		}
	}else{
		$form->outputFormular('body','formular.html');
	}
}else{
	General::getTpl()->assign('body','Sie sind bereits eingeloggt');
}
?>